unit uImage2;

interface

uses SysUtils, Dialogs, Graphics, Classes;

function GetImage(ImageFileName: String; ID: Integer): TBitmap;

implementation

function GetImage(ImageFileName: String; ID: Integer): TBitmap;
var
  RB, Buffer: TBitmap;
  I, J, U, xP, yP: Integer;
begin
  try
  RB := TBitmap.Create;
  Buffer:= TBitmap.Create;
  U := 0;
  Buffer.LoadFromFile(ImageFileName);
  if (ID < 0) then ID := 0;
  for J := 0 to (Buffer.Height div 32) - 1 do
  begin
      for I := 0 to (Buffer.Width div 32) - 1 do
      begin
        xP := 32 * I;
        yP := 32 * J;
        with RB do
        begin
          Width := 32;
          Height := 32;
        end;
        if (U = ID) then
        begin
          RB.Canvas.CopyRect(Bounds(0, 0, 32, 32), Buffer.Canvas, Bounds(xP, yP, 32, 32));
          Result := RB;
          Buffer.Free;
          Exit;
        end;
        Inc(U);
      end;
  end;
  Result := RB;
  except end;
  Buffer.Free;
end;

end.
